package com.example.todolist.controller;

import com.example.todolist.entity.Task;
import com.example.todolist.mapper.TaskMapper;
import com.example.todolist.service.TaskService;
import com.example.todolist.tools.ResponseBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/task")
public class TaskController {
    @Autowired
    private TaskService taskService;
    @Autowired
    private TaskMapper taskMapper;

    @PostMapping("/insertByTask")         //通过对象的方式插入task
    public ResponseBody<Integer> insert(@RequestParam Integer userId,@RequestBody Task task) {
        return taskService.insert(task);
    }

    @GetMapping("/findByTaskName")             //查找taskId
    public ResponseBody<Task> findByTaskName(@RequestParam Integer userId,@RequestParam String taskName)
    {
        return new ResponseBody<>(200,"success",taskMapper.findByTaskName(userId,taskName));
    }
    @DeleteMapping("/deleteByTaskId")
    public ResponseBody<Integer> deleteByTaskId(@RequestParam Integer userId,@RequestParam Integer taskId)
    {
        return new ResponseBody<>(200,"success",taskMapper.deleteByTaskId(userId,taskId));
    }
    @PostMapping("/checkForTask")
    public ResponseBody<Integer> checkForTask(@RequestParam Integer userId,@RequestParam Integer taskId)
    {
        return taskService.checkForTask(userId,taskId);
    }
    @PostMapping("/update")                  //更新task信息
    public ResponseBody<Integer> update(@RequestParam Integer userId,@RequestBody Task task)
    {
        return new ResponseBody<>(200,"success",taskService.update(task));
    }
    @GetMapping("/getTypeTask")
    public ResponseBody<List<Task>> getTypeTask(@RequestParam Integer userId,@RequestParam String taskType)
    {
        return new ResponseBody<>(200,"success",taskService.getTypeTask(userId,taskType));
    }
}
